<template>
  <s-layout
    title="我的"
    tabbar="/pages/index/user"
    navbar=""
    :bgStyle="template.style?.background"
    :navbarStyle="template.style?.navbar"
    onShareAppMessage
    :showFloatButton="true"
  >
    <!-- #ifdef APP-PLUS -->
    <view class="h-[2.75rem]"></view>
    <!-- #endif -->
    <s-block v-for="(item, index) in template.data" :key="index" :styles="item.style">
      <s-block-item :type="item.type" :data="item.data" :styles="item.style" />
    </s-block>
    <!-- 退出登录 -->
    <view class="p-4" v-if="isLogin">
      <view class="overflow-hidden py-3 w-full rounded-lg bg-[#0788C8] grid place-items-center" @tap="logout">
        <view class="font-medium text-[16px] text-[#FFFFFF]"> 退出登录 </view>
      </view>
    </view>
  </s-layout>
</template>

<script setup>
  import { computed } from 'vue';
  import { onShow, onPageScroll, onPullDownRefresh } from '@dcloudio/uni-app';
  import sheep from '@/sheep';

  // 隐藏原生tabBar
  uni.hideTabBar({
    fail: () => {},
  });

  const template = computed(() => sheep.$store('app').template.user);
  const isLogin = computed(() => sheep.$store('user').isLogin);

  onShow(() => {
    sheep.$store('user').updateUserData();
    // if (isLogin.value) {
    //   myInfo();
    // }
  });

  // function myInfo() {
  //   sheep.$api.yy.myInfo().then((res) => {
  //     uni.setStorageSync('is_shop', res.data);
  //   });
  // }

  onPullDownRefresh(() => {
    sheep.$store('user').updateUserData();
    setTimeout(function () {
      uni.stopPullDownRefresh();
    }, 800);
  });

  onPageScroll(() => {});

  // 退出登录
  function logout() {
    uni.showModal({
      title: '提示',
      content: '确认退出账号？',
      success: async function (res) {
        if (res.confirm) {
          const result = await sheep.$store('user').logout();
          if (result) {
            sheep.$router.go('/pages/index/user');
          }
        }
      },
    });
  }
</script>

<style lang="scss" scoped>
  :deep(.page-body) {
    background: linear-gradient(180deg, #0984c0 0%, #f1f6f7 400px) !important;
  }
  //ce698acc338e0f89aeb72307bec4afb8.png
  .logout-btn {
    width: 90%;
    height: 80rpx;
    line-height: 80rpx;
    text-align: center;
    background-color: #0788c8;
    color: #ffffff;
    border-radius: 40rpx;
    margin: 30rpx auto;
    font-size: 28rpx;
  }
</style>
